<?php
/**
 * CEOfox
 *
 * @copyright  Copyright 2011-2012 CEOfox, Inc.
 * @license    http://ceofox.com/pages/license
 * @version    $Id: topfollow.class.php 37088 2013-05-24 09:40:17 $
 * @author     CEOfox, Inc.
 */
?>
<?php
defined('PHPFOX') or extit('NO DICE!');
class Follow_Component_Block_Topfollow extends Phpfox_Component
{
    public function process()
    {
        Phpfox::isUser();
        if(!$aUser = $this->getParam('aUser'))
        {
            $aUser =  Phpfox::getService('user')->get(Phpfox::getUserId());
        }
        $bIsCurrentUser = false;
        $bIsLogin = (phpfox::getUserId() >0)? true: false;
        if(Phpfox::getUserId() == $aUser['user_id'])
        {
            $bIsCurrentUser = true;
        }
        $aTopFollwings = Phpfox::getService('follow')->getTopFollowing();
        $aResult = array();
        foreach($aTopFollwings as $aTopFollwing)
        {
            
            $aTemp = phpfox::getservice('user')->get($aTopFollwing['user_id']);
            $aTemp['total_followers'] = phpfox::GetService('follow')->countFollower($aTopFollwing['user_id']);
            $aTemp['total_following'] = phpfox::GetService('follow')->countFollowing($aTopFollwing['user_id']);
            if($aTemp['total_followers'] >= 1000 && $aTemp['total_followers'] < 1000000)
            {
                $aTemp['total_followers'] = $aTemp['total_followers']/ 1000;
                $aTemp['total_followers'] .='K';
            }
            elseif($aTemp['total_followers'] >= 100000)
            {
                $aTemp['total_followers'] =$aTemp['total_followers'] / 1000000;
                $aTemp['total_followers'] .='M';
            }

            if($aTemp['total_following'] >= 1000 && $aTemp['total_following'] < 1000000)
            {
                $aTemp['total_following'] = $aTemp['total_following']/ 1000;
                $aTemp['total_following'] .='K';
            }
            elseif($aTemp['total_following'] >= 100000)
            {
                $aTemp['total_following'] =$aTemp['total_following'] / 1000000;
                $aTemp['total_following'] .='M';
            }
            
            if($aTopFollwing['user_id'] == phpfox::GetUserId())
            {
                $aTemp['canFollow'] = 0;
            }
            else
            {
                if(Phpfox::getService('follow')->canFollow($aTopFollwing['user_id']))
                {
                    $aTemp['isFollow'] = Phpfox::getService('follow')->isFollow(Phpfox::getUserId(),$aTopFollwing['user_id'], 'user');
                    $aTemp['canFollow'] = 1;
                }
                else
                {
                    $aTemp['isFollow'] = 0;
                    $aTemp['canFollow'] = 0;
                }
            }
            $aResult[] = $aTemp;
            
        }
        $this->template()->assign(array(
                'sCoreUrl' =>phpfox::getParam('core.path'),
                'aTopFollwings' => $aResult,
                'aUser' => $aUser,
                'bIsLogin' => $bIsLogin,
                'sCoreUrl' =>phpfox::getParam('core.path'),
                'aCurrUser' => $aUser,
                'sType' => 'user',
                ));
        return 'block';
    }
}
?>

